package com.woniuxy.consume;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;


/**
 *
 */
@Component
@Slf4j
public class DelayConsume {
    @RabbitListener(queues = "delayQueue")
    public void receive(String msg, Channel channel, Message message){
        try {
            log.info("消费者接受消息");
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (Exception e) {
            e.printStackTrace();
            try {
                channel.basicNack(message.getMessageProperties().getDeliveryTag(),false,false);
            } catch (IOException ex) {
                e.printStackTrace();
            }
        }
    }
}
